#ifndef DRP631MQTTCLIENT_H
#define DRP631MQTTCLIENT_H

#include "zndevicebase.h"
#include "qmqttclient.h"
#include "qthread.h"
#include "iec103client.h"

class DRP631MqttClient : public ZNDeviceWork
{
	Q_OBJECT

public:
	DRP631MqttClient(QString hostname, quint16 port, QString username, QString password, QString clientid, IEC103Client* iec103Client, float pt, float ct);
	~DRP631MqttClient();

	void moveToThread(QThread* thread);
protected slots:
	void connected();
	void disconnected();
	void messageReceived(const QByteArray& message, const QMqttTopicName& topic = QMqttTopicName());

signals:
	void sendASUD(IEC103::ASDU* asdu);
	QVector<QVariant> getUniversalValue(uint32_t key);
protected:
	void timerEvent(QTimerEvent* event);
private:
	QMqttClient* client = nullptr;
	QString hostname;
	quint16 port;
	QString username;
	QString password;
	QString clientid;
	float PT = 1000;
	float CT = 1000;
	int workTimerID = -1;
	int reconnectTimerID = -1;
	bool connectFlag = false;
};
#endif